package com.le.tester.leetcode;

import com.le.tester.leetcode.common.ListNode;

import java.util.List;

/**
 * createTime：2021/8/25 9:22
 * description：给定一个链表，判断链表中是否有环。注意链表中的操作相当于static,修改了一处。，另一处也会跟着被修改,this相似
 */
public class Cycle {
    public boolean hasCycle(ListNode head) {
        if (null == head || null == head.next) {
            return false;
        }

        ListNode curNode = head;
        ListNode nextNode = head.next;
        while (curNode != nextNode) {
            if (nextNode == null || nextNode.next == null) {
                return false;
            }
            curNode = curNode.next;
            nextNode = nextNode.next.next;
        }

        return true;
    }

    public static void main(String[] args) {

    }
}
